package com.javasm.transfer.orderTransfer;

import com.javasm.domin.entity.orderEntity.B2cOrder;
import com.javasm.domin.entity.orderEntity.B2cReceiver;
import com.javasm.domin.entity.orderEntity.B2cReturnGoods;
import com.javasm.domin.vo.orderVo.OrderAndReceiver;
import com.javasm.domin.vo.orderVo.OrderGoodVo;
import com.javasm.mapper.B2cOrderMapper.B2cDataDictionaryMapper;
import com.javasm.mapper.B2cOrderMapper.B2cReceiverMapper;
import com.javasm.mapper.B2cOrderMapper.ReturnGoodsMapper;
import com.javasm.transfer.base.BaseTransfer;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.sound.midi.Receiver;
import java.util.List;

import static com.javasm.common.dictionary.InitContext.dic;

/**
 * @Author：liyangsong
 * @Version：1.0
 * @Date：2021/11/19-10:28
 * @Since:jdk1.8
 * @Description:
 */

/**
 * 转义
 */
@Component
public class OrderTransfer extends BaseTransfer<B2cOrder, OrderAndReceiver> {
    @Resource
    private B2cDataDictionaryMapper b2cDataDictionaryMapper;
    @Resource
    private ReturnGoodsMapper returnGoodsMapper;
    @Resource
    private B2cReceiverMapper b2cReceiverMapper;

    //1.订单动作 2 订单状态 3 业务类型 4 配送方式  5 支付方式  6订单分类订单类型 ',
    public List<OrderAndReceiver> Escape(List<B2cOrder> b2cOrderList) {
        List<OrderAndReceiver> orderAndReceiverListVo = super.toVO(b2cOrderList);
        List<B2cReceiver> b2cReceivers = b2cReceiverMapper.selectList(null);

        for (int i = 0; i < orderAndReceiverListVo.size(); i++) {
            B2cOrder b2cOrder = b2cOrderList.get(i);
            OrderAndReceiver orderAndReceiver = orderAndReceiverListVo.get(i);
            orderAndReceiver.setOrderAction(dic.get(1).get(b2cOrder.getOrderAction()));
            orderAndReceiver.setOrderStatus(dic.get(2).get(b2cOrder.getOrderStatus()));
            orderAndReceiver.setBusinessType(dic.get(3).get(b2cOrder.getBusinessType()));
            orderAndReceiver.setDeliveryStyle(dic.get(4).get(b2cOrder.getDeliveryStyle()));
            orderAndReceiver.setPaymentMethodId(dic.get(5).get(b2cOrder.getPaymentMethodId()));
            orderAndReceiver.setOrderType(dic.get(6).get(b2cOrder.getOrderType()));
            for (B2cReceiver b2cReceiver : b2cReceivers) {
                orderAndReceiver.setReceiverAdress(b2cReceiver.getReceiverAdress());
                orderAndReceiver.setVipId(b2cReceiver.getVipId());
                orderAndReceiver.setReceiverName(b2cReceiver.getReceiverName());
                orderAndReceiver.setPostalCode(b2cReceiver.getPostalCode());
                orderAndReceiver.setReceiverEmail(b2cReceiver.getReceiverEmail());
                orderAndReceiver.setReceiverPhone(b2cReceiver.getReceiverPhone());
                orderAndReceiver.setReceiverTelephone(b2cReceiver.getReceiverTelephone());
                orderAndReceiver.setPayName(b2cReceiver.getPayName());
                orderAndReceiver.setReceiverNotation(b2cReceiver.getReceiverNotation());
            }
        }
        return orderAndReceiverListVo;
    }

    /**
     * 查询单行订单信息 转义
     * @param b2cOrder
     * @return
     */
    public OrderAndReceiver setString(B2cOrder b2cOrder){
        OrderAndReceiver orderAndReceiver = super.toVO(b2cOrder);
        orderAndReceiver.setOrderAction(dic.get(1).get(b2cOrder.getOrderAction()));
        orderAndReceiver.setOrderStatus(dic.get(2).get(b2cOrder.getOrderStatus()));
        orderAndReceiver.setBusinessType(dic.get(3).get(b2cOrder.getBusinessType()));
        orderAndReceiver.setDeliveryStyle(dic.get(4).get(b2cOrder.getDeliveryStyle()));
        orderAndReceiver.setPaymentMethodId(dic.get(5).get(b2cOrder.getPaymentMethodId()));
        orderAndReceiver.setOrderType(dic.get(6).get(b2cOrder.getOrderType()));
        return orderAndReceiver;
    }
}
